<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class BookCommentsStart extends Model
{
    protected $table = 'book_comments_start';
    protected $casts = [
        'updated_at' => 'datetime:Y-m-d H:i:s',
        'created_at' => 'datetime:Y-m-d H:i:s',
    ];
    protected $fillable = [
        'comments_id', 'status', 'user_id', 'type'
    ];

    //评论属于某个用户
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    //评论点赞
    public function comments()
    {
        return $this->belongsTo(BookComments::class, 'id', 'comments_id');
    }

    public static function insertdata($comments_id, $type)
    {
        $user = Auth::guard('api')->user();
        $user_id = $user ? $user->id : 0;
        return self::create([
            'comments_id' => $comments_id,
            'user_id' => $user_id,
            'type' => $type,

        ]);
    }
}
